package autocode

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
    autocodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/service"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

type UserGoodsInfoApi struct {
}

var userGoodsInfoService = service.ServiceGroupApp.AutoCodeServiceGroup.UserGoodsInfoService


// CreateUserGoodsInfo 创建UserGoodsInfo
// @Tags UserGoodsInfo
// @Summary 创建UserGoodsInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.UserGoodsInfo true "创建UserGoodsInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /userGoodsInfo/createUserGoodsInfo [post]
func (userGoodsInfoApi *UserGoodsInfoApi) CreateUserGoodsInfo(c *gin.Context) {
	var userGoodsInfo autocode.UserGoodsInfo
	_ = c.ShouldBindJSON(&userGoodsInfo)
	if err := userGoodsInfoService.CreateUserGoodsInfo(userGoodsInfo); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteUserGoodsInfo 删除UserGoodsInfo
// @Tags UserGoodsInfo
// @Summary 删除UserGoodsInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.UserGoodsInfo true "删除UserGoodsInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /userGoodsInfo/deleteUserGoodsInfo [delete]
func (userGoodsInfoApi *UserGoodsInfoApi) DeleteUserGoodsInfo(c *gin.Context) {
	var userGoodsInfo autocode.UserGoodsInfo
	_ = c.ShouldBindJSON(&userGoodsInfo)
	if err := userGoodsInfoService.DeleteUserGoodsInfo(userGoodsInfo); err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteUserGoodsInfoByIds 批量删除UserGoodsInfo
// @Tags UserGoodsInfo
// @Summary 批量删除UserGoodsInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除UserGoodsInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /userGoodsInfo/deleteUserGoodsInfoByIds [delete]
func (userGoodsInfoApi *UserGoodsInfoApi) DeleteUserGoodsInfoByIds(c *gin.Context) {
	var IDS request.IdsReq
    _ = c.ShouldBindJSON(&IDS)
	if err := userGoodsInfoService.DeleteUserGoodsInfoByIds(IDS); err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateUserGoodsInfo 更新UserGoodsInfo
// @Tags UserGoodsInfo
// @Summary 更新UserGoodsInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.UserGoodsInfo true "更新UserGoodsInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /userGoodsInfo/updateUserGoodsInfo [put]
func (userGoodsInfoApi *UserGoodsInfoApi) UpdateUserGoodsInfo(c *gin.Context) {
	var userGoodsInfo autocode.UserGoodsInfo
	_ = c.ShouldBindJSON(&userGoodsInfo)
	if err := userGoodsInfoService.UpdateUserGoodsInfo(userGoodsInfo); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindUserGoodsInfo 用id查询UserGoodsInfo
// @Tags UserGoodsInfo
// @Summary 用id查询UserGoodsInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query autocode.UserGoodsInfo true "用id查询UserGoodsInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /userGoodsInfo/findUserGoodsInfo [get]
func (userGoodsInfoApi *UserGoodsInfoApi) FindUserGoodsInfo(c *gin.Context) {
	var userGoodsInfo autocode.UserGoodsInfo
	_ = c.ShouldBindQuery(&userGoodsInfo)
	if err, reuserGoodsInfo := userGoodsInfoService.GetUserGoodsInfo(userGoodsInfo.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"reuserGoodsInfo": reuserGoodsInfo}, c)
	}
}

// GetUserGoodsInfoList 分页获取UserGoodsInfo列表
// @Tags UserGoodsInfo
// @Summary 分页获取UserGoodsInfo列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query autocodeReq.UserGoodsInfoSearch true "分页获取UserGoodsInfo列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /userGoodsInfo/getUserGoodsInfoList [get]
func (userGoodsInfoApi *UserGoodsInfoApi) GetUserGoodsInfoList(c *gin.Context) {
	var pageInfo autocodeReq.UserGoodsInfoSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if err, list, total := userGoodsInfoService.GetUserGoodsInfoInfoList(pageInfo); err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败", c)
    } else {
        response.OkWithDetailed(response.PageResult{
            List:     list,
            Total:    total,
            Page:     pageInfo.Page,
            PageSize: pageInfo.PageSize,
        }, "获取成功", c)
    }
}
